/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	ComponentModelRenderer.h
*
*	Description -	
*
*	Comments	-	
*
*	Modification History:
*			Name			   Date					Description
*			MrCodeSushi	-	07/23/2012	-	Creation of this file
**************************************************************************************/
#ifndef _PSX_COMPONENT_MODEL_RENDERER_H_
#define _PSX_COMPONENT_MODEL_RENDERER_H_

#include "PulseSTD.h"
#include "IComponent.h"
#include "Model.h"
#include "RenderEntryList.h"

namespace Pulse
{
	class ComponentModelRenderer : public IComponent
	{
	public:

		ComponentModelRenderer( Actor *pOwner );

		virtual ~ComponentModelRenderer( void );

		virtual EErrorCode::Type Initialize( XMLElementPtr pElem );

		virtual const EComponent::Type GetType( void ) const { return EComponent::RENDERER; }

		static const EComponent::Type GetType_Static( void ) { return EComponent::RENDERER; }

		virtual const CHAR * GetName( void ) const { return PSX_String("Model Renderer"); }

		virtual void Update( FLOAT dt );

	public:

		RenderEntryList * GetRenderEntryList( void ) { return &m_renderEntries; }

		RenderEntryBindParameters * GetCameraSpecificParameters( const ComponentCamera *pCamera );

		// TODO: Add remove for cam specific params
		
	private:

		EErrorCode::Type RebuildRenderEntry( void );

		void ReleaseModel( void );

	private:

		// Delegates
		void OnRender( IEvent *pEvent );

		void OnTransform( IEvent *pEvent );

		void OnModelLoaded( IEvent *pEvent );
		
		void OnModelUnloaded( IEvent *pEvent );

	private:

		typedef HashTable<const ComponentCamera*, RenderEntryBindParameters> CamSpecificREList;

		Model						*m_pModel;
		CamSpecificREList			m_camSpecificREList;
		RenderEntryList				m_renderEntries;
		ParameterBinderMatrixRef	*m_pBinderTransform;

	};
}

#endif /* _PSX_COMPONENT_MODEL_RENDERER_H_ */